//
//  YKSVideoView.m
//  SoundLive
//
//  Created by macintosh on 16/8/9.
//  Copyright © 2016年 Yue Shen. All rights reserved.
//

#import "YKSVideoView.h"
#import <AVFoundation/AVFoundation.h>
#import "YKLBPlayerCore.h"
#import "UIDevice+InterfaceOrientation.h"

@interface YKSVideoView ()

@property (weak, nonatomic) IBOutlet UIButton *fullScreenbtn;
@property (weak, nonatomic) IBOutlet UIButton *playBtn;

@property (nonatomic, strong) YKLBPlayerCore *playerCore;

@end

@implementation YKSVideoView

+ (Class)layerClass
{
    return [AVPlayerLayer class];
}

- (void)awakeFromNib
{
    _playerCore = [[YKLBPlayerCore alloc] init];
    [(AVPlayerLayer *)[self layer] setPlayer:_playerCore.player];
}

- (void)setContentURL:(NSURL *)contentURL
{
    [_playerCore setURL:contentURL];
}

- (IBAction)backBtnClicked:(UIButton *)sender {
    if (_backClickedBlock) {
        _backClickedBlock();
    }
}

- (IBAction)soundSwitchClicked:(UIButton *)sender {
    if (_switchClickedBlock) {
        _switchClickedBlock();
    }
}

- (IBAction)fullScreenBtnClicked:(UIButton *)sender {
    if (sender.isSelected) {
        [[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
    } else {
        [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
    }
    
    sender.selected = !sender.selected;
}

- (IBAction)playBtnClicked:(UIButton *)sender {
    if (sender.isSelected) {
        [_playerCore play];
    } else {
        [_playerCore pause];
    }
    
    sender.selected = !sender.selected;
}

@end
